<?php
namespace Kuoqi\Core;

/**
 * worker的相关模块的信息
 * Class Kworker
 * @package Kuoqi\Core
 */
class Kworker{

    /**
     * Kworker constructor.
     */
    public function __construct()
    {

    }

    //获取基础信息
    public function info(){
        $com = new \COM('KuoqiWorker.worker');
        return $com->info();
    }

    /**
     * 视频转视频流数据
     * createby kuoqi at 2022/8/26 16:26
     * @param $file
     * @param $output
     * @param array $options
     * @return mixed
     */
    public function ffmpegVideo2m3u8($file,$output,$options = array()){
        $options = array_merge($options,array(
            '-force_key_frames'=>"expr:gte(t,n_forced*1)",
            '-bsf:v'=>'h264_mp4toannexb',
            '-hls_time'=>5,
            '-hls_list_size'=>0,
            //'-s'=>'1280x720',
            '-f'=>'hls'
        ));
        $output = \Kuoqi\Route::str2rootpath($output);
        $comm = '-re -i '.\Kuoqi\Route::str2rootpath($file);
        foreach ($options as $k=>$v){
            $comm .= sprintf(' %s %s',$k,$v);
        }
        $comm .= ' '.$output;
        $com = new \COM('KuoqiWorker.worker');
        return $com->ffmpeg($comm);
    }
}

